package com.song.shop.controller;

import com.song.shop.entity.Shop;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.Objects;

/**
 * @author Song Yinghui
 * @date 2018/10/19
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/test1")
public class TestController {


    @GetMapping("test")
    public ResponeEntity test(@RequestParam("paras") String[] list, Integer a ){
        System.out.println(list.length);
        ResponeEntity entity = new ResponeEntity();
        entity.setName("测试");
        entity.setCode(null);
        System.out.println("当前线程明湖曾==============="+Thread.currentThread().getName());
        return entity ;
    }

    @RequestMapping(value = "/ceshi")
    public String test1(Shop shop, HttpServletRequest request){
        System.out.println(shop);
        System.out.println(shop.getShopName());

        Cookie[] cookies = request.getCookies();
        String str  = "";
        for (Cookie cookie : cookies){
            str += cookie.getName()+cookie.getValue();
        }
        return "result"+shop+str;
    }

    @RequestMapping("requestbody")
    public String testRequestBody(@RequestBody Shop shop , @RequestParam("id") String id ){
        System.out.println(id);
        System.out.println(shop);
        return shop.toString();
    }

    class ResponeEntity{
        private String name ;
        private String code ;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

         public void setCode1(String code) {
            this.code = code;
        }

        @Override
        public String toString() {
            return "ResponeEntity{" +
                    "name='" + name + '\'' +
                    ", code='" + code + '\'' +
                    '}';
        }
    }
}
